-module(new_name_server).
-export([init/0, add/2, whereis/1, handle/2, all_names/0]).

-import(server3, [rpc/2]).

% client routines
all_names() -> rpc(nameserver, allnames).
add(Name, Place) -> rpc(nameserver, {add, Name, Place}).
whereis(Name) -> rpc(nameserver, {whereis, Name}).

% callback routines
init() -> 
	io:fwrite("Initializing module..."),
	dict:new().

handle({add, Name, Place}, Dict) 	-> {ok, dict:store(Name, Place, Dict)};
handle(allnames, Dict) 				-> {dict:fetch_keys(Dict), Dict};
handle({whereis, Name}, Dict) 		-> {dict:find(Name, Dict), Dict}.
